import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;

import javax.swing.JPanel;


public class backgroundPanel extends JPanel{
	private Image img;
	private int x; 
	private int y;
	private int width;
	private int height;
	
	public backgroundPanel(String imgName, int initX, int initY, int initWidth, int initHeight){
		loadImage(imgName);
		x = initX;
		y = initY;
		width = initWidth;
		height = initHeight;
	}
	
	public void loadImage(String imgName){
		Toolkit tk = Toolkit.getDefaultToolkit();
		Image t0 = tk.createImage(imgName);
		MediaTracker tracker = new MediaTracker(backgroundPanel.this);
		tracker.addImage(t0, 0);
		try { 
			tracker.waitForAll(); 
		}
		catch(InterruptedException ie) {}
		System.out.println("Load Image: "+imgName);
		img = t0;
	}

	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(img, x, y, width, height, null);
	}
}
